﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Business_Logic_Layer;


namespace Money_Dance
{
    public partial class LoginForm : Form
    {
        //SysDataContext data = new SysDataContext();
        BUSS BUS = new BUSS();
        Bitmap background = new Bitmap(@"C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\Final\Money Dance\bin\Debug\Background.png", true);
        
        public LoginForm()
        {
            InitializeComponent();
            this.BackgroundImage = background;
        }

        private void btn_Login_Click(object sender, EventArgs e)
        {  
            if (BUS.CountUser(this.TbxTenDangNhapLogin.Text, this.TbxMatKhauLogin.Text) > 0)
            {          

                MoneyDance GetId = new MoneyDance(BUS.GetIdUser(this.TbxTenDangNhapLogin.Text));
                UserControlTrangchu Id = new UserControlTrangchu(BUS.GetIdUser(this.TbxTenDangNhapLogin.Text));
                MoneyDance frmMoneyDance = new MoneyDance();
                frmMoneyDance.MdiParent = this.MdiParent;
                frmMoneyDance.Show();
            }
            else
            {
                MessageBox.Show("Loi dang nhap");
            }
        }

        private void btn_Registry_Click(object sender, EventArgs e)
        {
            
            if (this.TbxMatKhauRigestry.Text == this.TbxMatKhauConfirmRigestry.Text)
            {
                BUS.InsertUser(this.TbxTenDangNhapRigestry.Text, this.TbxMatKhauRigestry.Text, this.TbxEmail.Text);

                BUS.InserAccount(BUS.GetIdUser(), "Checking", "0", 0);
                BUS.InserAccount(BUS.GetIdUser(), "Saving", "0", 0);   
              
                MoneyDance GetId = new MoneyDance(BUS.GetIdUser());
                MoneyDance frmMoneyDance = new MoneyDance();
                frmMoneyDance.MdiParent = this.MdiParent;
                frmMoneyDance.Show();
            }            
            
        }

        private void LoginForm_Load(object sender, EventArgs e)
        {
            
        }

        private void btn_Login_Enter(object sender, EventArgs e)
        {
             if (BUS.CountUser(this.TbxTenDangNhapLogin.Text, this.TbxMatKhauLogin.Text) > 0)
            {          

                MoneyDance GetId = new MoneyDance(BUS.GetIdUser(this.TbxTenDangNhapLogin.Text));
                UserControlTrangchu Id = new UserControlTrangchu(BUS.GetIdUser(this.TbxTenDangNhapLogin.Text));
                MoneyDance frmMoneyDance = new MoneyDance();
                frmMoneyDance.MdiParent = this.MdiParent;
                frmMoneyDance.Show();
            }
            else
            {
                MessageBox.Show("Loi dang nhap");
            }
        }
        
    }
}
